package com.capgemini.cn.authority.core.security;

import com.capgemini.cn.authority.core.cache.RedisCachingAuthenticator;
import org.pac4j.core.authorization.generator.AuthorizationGenerator;
import org.pac4j.core.credentials.UsernamePasswordCredentials;
import org.pac4j.core.credentials.authenticator.Authenticator;
import org.pac4j.core.profile.CommonProfile;
import org.pac4j.core.profile.creator.ProfileCreator;
import org.pac4j.http.client.direct.DirectBasicAuthClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

/**
 * Created at 2017/8/30
 *
 * @author Andriy
 */
@Component(value = SecurityClient.COMPONENT_NAME)
public class SecurityClient extends DirectBasicAuthClient {

    public static final String COMPONENT_NAME = "securityClient";

    public SecurityClient() {
    }

    public SecurityClient(Authenticator usernamePasswordAuthenticator) {
        super(usernamePasswordAuthenticator);
    }

    public SecurityClient(Authenticator usernamePasswordAuthenticator, ProfileCreator profileCreator) {
        super(usernamePasswordAuthenticator, profileCreator);
    }

    @Autowired
    @Qualifier(value = RedisCachingAuthenticator.COMPONENT_NAME)
    @Override
    public void setAuthenticator(Authenticator<UsernamePasswordCredentials> authenticator) {
        super.setAuthenticator(authenticator);
    }

    @Autowired
    @Qualifier(value = SecurityAuthorizationGenerator.COMPONENT_NAME)
    @Override
    public void setAuthorizationGenerator(AuthorizationGenerator<CommonProfile> authorizationGenerator) {
        super.setAuthorizationGenerator(authorizationGenerator);
    }
}
